#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	int n, m, c, t;
	cin >> n >> m >> c >> t;
	vector<vector<int>> gh(n + 1);
	vector<int> vis(n + 1, 0);

	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		gh[u].push_back(v);
		gh[v].push_back(u);
	}

	queue<int> q;
	q.push(c);
	vis[c] = 1;

	while (!q.empty()) {
		t++;

		int size = q.size();
		while (size--) {
			int u = q.front();
			q.pop();
			for (auto v : gh[u]) {
				if (!vis[v]) {
					vis[v] = 1;
					q.push(v);
				}
			}
		}
	}
	cout << t << endl;
	return 0;
}